package controller

import (
	"github.com/gofiber/fiber"
	"gowork/weChat/model"
	"strconv"
)

type WeChatController struct {
	WechatMoments *model.WechatMoments
	Friends *model.Friends
}

func (wcc *WeChatController)ViewYourCircleOfGriends(c *fiber.Ctx){

	wcc.WechatMoments = new(model.WechatMoments)

	userId := c.FormValue("userId")
	pageSizeStr := c.FormValue("pageSize")
	pageNoStr := c.FormValue("pageNo")

	pageSize, _ := strconv.Atoi(pageSizeStr)
	pageNo, _ := strconv.Atoi(pageNoStr)

	res , err := wcc.WechatMoments.ViewYourCircleOfGriends(userId, pageSize, pageNo)
	if err != nil{
		c.JSON(fiber.Map{
			"code": 500,
			"data": nil,
			"message": err.Error(),
		})
		return
	}

	c.JSON(fiber.Map{
		"code": 200,
		"data": res,
		"message": "成功",
	})
	return
}

func (wcc *WeChatController)AsyncOperation(c *fiber.Ctx){

	wcc.WechatMoments = new(model.WechatMoments)
	wcc.Friends = new(model.Friends)

	var f model.Friends
	c.BodyParser(&f)

	res , err := wcc.Friends.AsyncOperation(&f)
	if err != nil{
		c.JSON(fiber.Map{
			"code": 500,
			"data": nil,
			"message": err.Error(),
		})
		return
	}

	c.JSON(fiber.Map{
		"code": 200,
		"data": res,
		"message": "成功",
	})
	return
}